package com.atguigu.locks.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author : leimingchao
 * @date Date : 2021年11月30日 21:43
 */
@RestController
public class ThreadPoolController {

    @Qualifier(value = "mainThreadPoolExecutor")
    @Autowired
    private ThreadPoolExecutor threadPoolExecutor;

    @Qualifier(value = "otherThreadPoolExecutor")
    @Autowired
    private ThreadPoolExecutor otherThreadPoolExecutor;

    @GetMapping(value = "/thread/status")
    public Map<String,Object> threadPoolStatus() {
        Map<String,Object> map = new HashMap<>();
        map.put("ActiveCount",threadPoolExecutor.getActiveCount());
        map.put("corePoolSize",threadPoolExecutor.getCorePoolSize());
        return map;
    }
}
